<!--
 * @Author: ChenCaoYang
 * @Date: 2021-05-29 19:27:52
 * @LastEditors: chencaoyang
 * @LastEditTime: 2021-06-15 13:54:10
-->
<template>
  <div class="container">
    <el-main>
      <el-table
        ref="multipleTable"
        :data="productData"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        header-row-class-name="header"
        cell-class-name="bodyer"
      >
        <el-table-column type="selection" width="50"> </el-table-column>
        <el-table-column prop="all" label="全选" width="55"> </el-table-column>
        <el-table-column prop="goods" label="商品" width="420">
          <template slot-scope="scope">
            <div style="height: 100px" class="goods_box">
              <div style="max-width: 100px; height: 100px; min-width: 100px">
                <el-image
                  fit="cover"
                  :src="scope.row.titlePicStr"
                  alt=""
                  style="width: 100%; height: 100%"
                />
              </div>
              <div class="goods_info">
                <p>{{ scope.row.productName }}</p>
                <p>{{ scope.row.productSpecs }}</p>
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="单价" width="100" prop="price">
          <template slot-scope="scope">
            <div class="price">￥{{ scope.row.productPrice }}</div>
          </template>
        </el-table-column>
        <el-table-column label="规格" width="160" prop="spe">
          <template slot-scope="scope">
            <div>{{ scope.row.productSpecs }}</div>
          </template>
        </el-table-column>
        <el-table-column label="数量" width="140" prop="number">
          <template slot-scope="scope">
            <el-input-number
              v-model="scope.row.productNum"
              :min="1"
              :max="99"
              @change="
                (newValue, oldValue) =>
                  putShopCart(
                    newValue,
                    oldValue,
                    scope.row.productId,
                    scope.row.specsId
                  )
              "
            ></el-input-number>
          </template>
        </el-table-column>
        <el-table-column prop="count" label="总计" width="120">
          <template slot-scope="scope">
            <div class="count">
              ￥{{ (scope.row.productNum * scope.row.productPrice).toFixed(2) }}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="140">
          <template slot-scope="scope">
            <div class="oper">
              <p @click="del(scope.row.shopCatrId)">删除</p>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <!-- 确认收货 -->
      <div class="isOver">
        <el-button type="warning" round size="medium" @click="toBuy()"
          >结 算</el-button
        >
      </div>
    </el-main>
  </div>
</template>

<script>
import { get_data } from "../../../../utils/utils";
export default {
  name: "allProducts",
  data() {
    return {
      dialogVisible: false,
      multipleSelection: [],
      tuikuanInfo: "",
      productData: [],
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    getData() {
      let userInfo = get_data("userInfo");
      userInfo = JSON.parse(userInfo);
      // alert(userInfo);
      this.$http
        .fetch(this.$apiPath.getShopCart, {
          method: "get",
          params: {
            customerId: userInfo.id,
          },
        })
        .then((res) => {
          this.productData = res.data;
        });
    },
    toBuy() {
      if (this.multipleSelection.length > 0) {
        let url = [];
        this.multipleSelection.forEach((item, index) => {
          url.push(item.shopCatrId);
        });
        this.$router.push({
          path: `/settlement?productId=${url.join(",")}`,
        });
      } else {
        this.$message("请先选择商品");
      }
    },
    del(shopCatrId) {
      let userInfo = get_data("userInfo");
      userInfo = JSON.parse(userInfo);
      this.$http
        .fetch(this.$apiPath.delShopCart, {
          method: "post",
          data: {
            customerId: userInfo.id,
            shopCatrId: shopCatrId,
          },
        })
        .then((res) => {
          if (res.code == 200) {
            this.$message("删除成功");
            setTimeout(() => {
              this.productData = [];
              this.getData();
            }, 500);
          }
        });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(this.multipleSelection);
    },
    wuliu() {
      this.$router.push({
        path: "/order/userCards/logisticsDetails",
      });
    },
    handleSelect() {},
    tuihuo() {
      this.dialogVisible = true;
    },
    postComments() {
      this.$router.push({
        path: "/order/postComments",
      });
    },
    putShopCart(newValue, oldValue, productId, specsId) {
      let userInfo = get_data("userInfo");
      userInfo = JSON.parse(userInfo);

      this.$http
        .fetch(this.$apiPath.putShopCart, {
          method: "post",
          data: {
            addOrDel: newValue > oldValue ? 1 : 0,
            customerId: userInfo.id,
            productId: productId,
            specsId: specsId,
          },
        })
        .then((res) => {
          console.log(res);
        });
    },
  },
};
</script>

<style lang="less" scoped>
.container {
  /deep/.el-table th > .cell {
    text-align: center;
  }
  /deep/.bodyer {
    text-align: center;
  }
  /deep/.el-checkbox__input.is-checked .el-checkbox__inner {
    background-color: #cf975a;
    border: #cf975a;
  }
  /deep/.el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #cf975a;
    border: #cf975a;
  }
  /deep/.el-checkbox__inner {
    border-radius: 50% !important;
  }
  /deep/.el-input-number {
    width: 100%;
  }
  .goods_box {
    box-sizing: border-box;
    display: flex;
    .goods_info {
      padding: 25px 0;
      margin-left: 23px;
      p:first-child {
        font-size: 14px;
        font-family: PingFangSC;
        font-weight: 400;
        color: #666666;
        margin-bottom: 10px;
      }
      p:last-child {
        font-size: 12px;
        font-family: Source Han Sans CN;
        font-weight: 300;
        color: #999999;
      }
    }
  }
  .price,
  .count {
    font-size: 18px;
    font-weight: 500;
    color: #ff9933;
  }
  .oper {
    .is-round {
      padding: 9px 29px;
    }
    p:first-child {
      font-size: 14px;
      font-weight: 400;
      color: #999999;
      cursor: pointer;
    }
    .wuliu {
      font-size: 14px;
      font-weight: 400;
      color: #ff9933;
      cursor: pointer;
      margin-bottom: 8px;
    }
  }
  .isOver {
    overflow: hidden;
    padding-right: 50px;
    margin-top: 67px;
    button {
      float: right;
      width: 150px;
      padding: 17px 12px;
      background: #cf975a;
      border-radius: 28px;
    }
  }
  .el-dialog__title {
    font-size: 30px;
    font-weight: 500;
    color: #5c5f68;
    margin-top: 10px;
  }
  .content {
    .title {
      font-size: 18px;
      font-weight: 400;
      color: #333333;
    }
    .product_info {
      display: flex;
      margin-top: 20px;
      align-items: center;
      margin-bottom: 20px;
      .img {
        width: 100px;
        height: 100px;
        margin-right: 24px;
        img {
          width: 100%;
          height: 100%;
          border-radius: 5px;
        }
      }
      .product_name {
        height: 49px;
        width: 406px;
        .title {
          margin-bottom: 10px;
          font-size: 14px;
          font-weight: 600;
          color: #666666;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        .product_name {
          font-size: 12px;
          font-weight: 300;
          color: #9999;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
      }
    }
    .test {
      margin-top: 20px;
      margin-bottom: 30px;
    }
    .money {
      span:last-child {
        float: right;
        font-size: 18px;
        font-weight: 400;
        color: #ff9933;
      }
    }
    .submit {
      padding-right: 0;
      display: flex;
      justify-content: center;
    }
  }
  /deep/.footer {
    padding: 0;
    margin: 0 auto;
    margin-top: 30px;
    margin-bottom: 33px;
    background-color: #ffffff;
    .btn-prev {
      width: 74px;
      height: 30px;
      border: 1px solid #c7c7c7;
      border-radius: 15px;
    }
    .btn-next {
      width: 74px;
      height: 30px;
      border: 1px solid #c7c7c7;
      border-radius: 15px;
      color: #999999;
    }
    .el-pager li {
      width: 30px;
      height: 30px;
      border: 1px solid #c7c7c7;
      border-radius: 15px;
      color: #999999;
    }
    .el-pager {
      .number {
        text-align: center;
        padding: 0;
      }
      //   .number:hover {
      //     color: #999999 !important;
      //   }
      li:not(.active).number:hover {
        color: #999999 !important;
      }
    }
    .el-pager li:not(.disabled).active {
      background-color: #cf975a;
    }
  }
}
</style>
